/*
socket options
*/

#ifndef SOCKET_OPS_H
#define SOCKET_OPS_H

#ifndef WIN32
#ifndef SOCKET_ERROR
#define SOCKET_ERROR -1
#endif
#define SOCKET int

#define ERROR_WOULDBLOCK EWOULDBLOCK
#define ERROR_INPROGRESS EINPROGRESS

#else

#define ERROR_WOULDBLOCK WSAEWOULDBLOCK
#define ERROR_INPROGRESS WSAEINPROGRESS
#endif

namespace SocketOps
{
	void InitSocket();
	// Create file descriptor for socket i/o operations.
	SOCKET CreateTCPFileDescriptor();

	// Disable blocking send/recv calls.
	bool Nonblocking(SOCKET fd);

	// Enable blocking send/recv calls.
	bool Blocking(SOCKET fd);

	// Disable nagle buffering algorithm
	bool DisableBuffering(SOCKET fd);

	// Enables nagle buffering algorithm
	bool EnableBuffering(SOCKET fd);

	// Set internal buffer size to socket.
	bool SetRecvBufferSize(SOCKET fd, uint8 size);

	// Set internal buffer size to socket.
	bool SetSendBufferSize(SOCKET fd, uint8 size);

	// Set timeout, in seconds
	bool SetTimeout(SOCKET fd, int32 timeoutS);

	uint32 GetRecvTimeout(SOCKET fd);

	uint32 GetSendTimeout(SOCKET fd);

	// Closes socket completely.
	void CloseSocket(SOCKET fd);

	// Sets SO_REUSEADDR
	void ReuseAddr(SOCKET fd);

	uint32	GetErrorNumber();
	uint32	GetSocketError(SOCKET fd);
};

#endif

